package JAVA300.第十一章多线程;

/**
 * 线程优先级
 */

public class thread_12_priority {
    public static void main(String[] args) {
        System.out.println(Thread.currentThread().getPriority());//default 5

        MyThread myThread = new MyThread();
        Thread thread1 = new Thread(myThread,"thread1");//mythread->5
        Thread thread2 = new Thread(myThread,"thread2");
        Thread thread3 = new Thread(myThread,"thread3");
        Thread thread4 = new Thread(myThread,"thread4");
        Thread thread5 = new Thread(myThread,"thread5");

        //设置优先级一定在start之前
        thread1.setPriority(Thread.MAX_PRIORITY);
        thread2.setPriority(Thread.MAX_PRIORITY);
        thread3.setPriority(Thread.MIN_PRIORITY);
        thread4.setPriority(Thread.MIN_PRIORITY);
        thread5.setPriority(Thread.MIN_PRIORITY);

        thread1.start();
        thread2.start();
        thread3.start();
        thread4.start();
        thread5.start();


    }

}

class MyThread implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"->"+Thread.currentThread().getPriority());
        Thread.yield();

    }
}
